package org.lanqiao.tjut.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lanqiao.tjut.bean.CourseBean;
import org.lanqiao.tjut.bean.EduScoreAllInfoViewBean;
import org.lanqiao.tjut.bean.TeacherBean;
import org.lanqiao.tjut.myUtils.MyUtils;
import org.lanqiao.tjut.service.ServiceFactory;

public class StuInfoManageServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 学生信息管理
		String strOpt = request.getParameter("opt");
		if (strOpt != null && strOpt.trim().equals("0")) {
			// 学生成绩录入页面的跳转数据准备
			// 当前老师所教授的课程列表
			TeacherBean teaB = (TeacherBean) request.getSession().getAttribute("loginedUsersB");
			int teaId = MyUtils.obj2Int(teaB.getTeaid());
			List<CourseBean> lstCourse = ServiceFactory.getStuInfoManagerServiceInstance().getCourseInfoByTeaId(teaId);
			// 发送前台进行显示
			request.getSession().setAttribute("teaB", teaB);

			request.getSession().setAttribute("lstCourse", lstCourse);

			request.getRequestDispatcher("logined/StuInfoManager/StuScoreInput.jsp").forward(request, response);
		} else if (strOpt != null && strOpt.trim().equals("1")) {
			// 查询当前课程的学生信息
			int teaId = MyUtils.obj2Int(request.getParameter("txtTeacher"));
			int courseId = MyUtils.obj2Int(request.getParameter("txtCourse"));
			List<EduScoreAllInfoViewBean> lstStuInfo4Grade = ServiceFactory.getStuInfoManagerServiceInstance()
					.getStuInfoBy4Grade(teaId, courseId);
			request.getSession().setAttribute("lstStuInfo4Grade", lstStuInfo4Grade);

			request.getRequestDispatcher("logined/StuInfoManager/StuScoreInput.jsp").forward(request, response);
		} else if (strOpt != null && strOpt.trim().equals("2")) {
			//获取新增数据串
			String strParasScores = request.getParameter("txtscores");
			MyUtils.logger_console.debug("strParasScores---"+strParasScores);
			int i = ServiceFactory.getStuInfoManagerServiceInstance().updateStuScore(strParasScores);
		}

	}

}
